package com.wanxi.education.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanxi.education.mapper.CertificateMapper;
import com.wanxi.education.mapper.CourseMapper;
import com.wanxi.education.model.vo.advertandcertificate.AdvertAddVo;
import com.wanxi.education.model.vo.advertandcertificate.CertificateAddVo;
import com.wanxi.education.model.vo.advertandcertificate.CertificateFindPageVo;
import com.wanxi.education.model.vo.advertandcertificate.CertificateFrontVo;
import com.wanxi.education.service.CertificateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: yanguangqiong
 * @Description:
 * @Date: Created in 2021/9/28
 * @Version: 1.0
 */
@Service
public class CertificateServiceImpl implements CertificateService {
    @Autowired
    private CertificateMapper certificateMapper;

    @Override
    public PageInfo findPage(CertificateFindPageVo certificateFindPageVo) {
        PageHelper.startPage(certificateFindPageVo.getPageNum(),certificateFindPageVo.getPageSize());
        List<CertificateAddVo> list = certificateMapper.findPage(certificateFindPageVo);
        PageInfo<CertificateAddVo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public CertificateAddVo findById(Long certificateId) {
        CertificateAddVo certificateAddVo = certificateMapper.findById(certificateId);
        return certificateAddVo;
    }
//修改证书状态
    @Override
    public void updateStatus(Long certificateId) {
        certificateMapper.updateStatus(certificateId);
    }
//删除
    @Override
    public void delete(Long certificateId) {
        certificateMapper.delete(certificateId);
    }

    @Override
    public void add(CertificateAddVo certificateAddVo) {
        certificateMapper.add(certificateAddVo);
    }

    @Override
    public void update(CertificateAddVo certificateAddVo) {
        certificateMapper.update(certificateAddVo);
    }

//    前台显示证书详情
    @Override
    public CertificateFrontVo findByIdForFront(Long courseId) {
        Long certificateId= certificateMapper.findIdByCourse(courseId);
       CertificateFrontVo certificateFrontVo= certificateMapper.findByIdForFront(certificateId);
        return certificateFrontVo;
    }
}
